<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div class="search" v-show="showSearch">
        <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
          <el-form-item label="情景名称" prop="profilename">
            <el-input v-model="queryParams.profilename" placeholder="请输入情景名称" clearable @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </transition>

    <el-card shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="Plus" @click="handleAdd">新增</el-button>
          </el-col>
          <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" />
        </el-row>
      </template>

      <el-table v-loading="loading" :data="profileList">
        <el-table-column label="id" align="center" prop="id" v-if="false" />
        <el-table-column label="情景名称" align="center" prop="profilename" />
        <el-table-column label="创建时间" align="center" prop="createTime" width="180">
          <template #default="scope">
            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="下发" align="center">
          <template #default="scope">
            <el-button type="primary" icon="UploadFilled" @click="handleIssue(scope.row)">下发</el-button>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-tooltip content="修改" placement="top">
              <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" />
            </el-tooltip>
            <el-tooltip content="添加设备" placement="top">
              <el-button link type="primary" icon="CirclePlus" @click="handleAddEqu(scope.row)" />
            </el-tooltip>
            <el-tooltip content="查询" placement="top">
              <el-button link type="primary" icon="Search" @click="handleQueryEqu(scope.row)" />
            </el-tooltip>
            <el-tooltip content="删除" placement="top">
              <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" />
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        :total="total"
        v-model:page="queryParams.pageNum" 
        v-model:limit="queryParams.pageSize" 
        @pagination="getList" 
      />
    </el-card>
    <!-- 新增或修改情景对话框 -->
    <el-dialog
      :title="dialog.title"
      v-model="dialog.visible"
      width="500px"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      append-to-body
      destroy-on-close
    >
      <el-form ref="profileFormRef" :model="profileForm" :rules="rules" label-width="80px">
        <el-form-item label="情景名称" prop="profilename">
          <el-input v-model="profileForm.profilename" placeholder="请输入情景名称" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <!-- 绑定设备对话框 -->
    <el-dialog
      title="新增设备"
      v-model="dialog1.visible"
      width="50%"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      append-to-body
      destroy-on-close
    >
      <el-form ref="devFormRef" :model="devForm" :inline="true" label-width="40px">
        <el-form-item label="区域">
          <el-cascader
            v-model="cascaderValue" 
            placeholder="选择区域" 
            :options="options" 
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="tabGroupSelect">选择群组</el-button>
        </el-form-item>
      </el-form>
      <!-- 设备列表 -->
      <el-table v-show="Obar" :data="drawerList" bordered @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column label="设备名称" align="center" prop="devname" />
        <el-table-column label="设备地址" align="center" prop="addr" />
        <el-table-column label="所属网关" align="center" prop="imei" />
      </el-table>
      <pagination
        v-show="Obar"
        :total="total1"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getDrawerList"
      />
      <!-- 群组列表 -->
      <el-table v-show="!Obar" :data="groupList" bordered>
        <el-table-column label="群组名称" align="center" prop="groupname" />
        <el-table-column label="操作" align="center">
          <template #default="scope">
            <el-button type="primary">绑定</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="!Obar"
        :total="total2"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getGroup"
      />
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="submitForm1">确 定</el-button>
          <el-button @click="cancel1">取 消</el-button>
        </div>
      </template>
    </el-dialog>
    <!-- 查询>设备列表抽屉 -->
    <el-drawer 
      placement="right" 
      :closable="false" 
      :title="drawer.title"
      v-model="drawer.visible"
      @update:model-value="handleDrawerClose"
      size="50%"
    >
      <el-button style="position: absolute; right: 20px; z-index: 10" type="primary">删除全部</el-button>
      <el-tabs type="card" v-model="activeName" @tab-click="tabChange">
        <el-tab-pane label="设备" name="first">
          <div class="swld">
            <p>批量设置当前页</p>
            <el-button type="primary">开</el-button>
            <el-button type="primary">关</el-button>
            <el-slider :max="99" :min="1" />
          </div>
          <el-table :data="drawerList1" bordered>
            <el-table-column label="序号" type="index" width="50" align="center" />
            <el-table-column label="设备名称" align="center" prop="devname" />
            <el-table-column label="设备地址" align="center" prop="addr" />
            <el-table-column label="所属网关" align="center" prop="imei" />
            <el-table-column label="开关" align="center" prop="sw">
            <template #default="scope">
              <el-switch v-model="scope.row.sw" active-value="0" inactive-value="1" />
            </template>
          </el-table-column>
          <el-table-column label="亮度" align="center" prop="ld">
            <template #default="scope">
              <el-slider v-model="scope.row.ld" :max="99" :min="1" :default-value="0" />
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template #default="scope">
              <el-tooltip content="删除" placement="top">
                <el-button link type="primary" icon="Delete" />
              </el-tooltip>
              </template>
            </el-table-column>
          </el-table>
          <pagination
            :total="total3"
            v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize"
            @pagination="getDrawerList1"
          />
        </el-tab-pane>
        <el-tab-pane label="群组" name="second">
          <el-table :data="groupList1" bordered>
            <el-table-column label="群组名称" align="center" prop="groupname" />
            <el-table-column label="开关" align="center" prop="sw">
              <template #default="scope">
                <el-switch v-model="scope.row.sw" active-value="0" inactive-value="1" />
              </template>
            </el-table-column>
            <el-table-column label="亮度" align="center" prop="ld">
              <template #default="scope">
                <el-slider v-model="scope.row.ld" :max="99" :min="1" :default-value="0" />
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template #default="scope">
                <el-tooltip content="删除" placement="top">
                  <el-button link type="primary" icon="Delete" />
                </el-tooltip>
              </template>
            </el-table-column>
          </el-table>
          <pagination
            :total="total4"
            v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize"
            @pagination="getGroup1"
          />
        </el-tab-pane>
      </el-tabs>
    </el-drawer>
  </div>
</template>

<script setup name="Profile" lang="ts">
import { ref } from 'vue'
import { ComponentInternalInstance } from 'vue'
import { FormInstance } from 'element-plus'
const { proxy } = getCurrentInstance() as ComponentInternalInstance

const cascaderValue = ref([])
const temp = [
    {
        "id": "1753588848392179714",
        "buildingName": "煤仓",
        "totalfloor": null,
        "createName": "6e82717e7e95406ca4f356ce19c4373a",
        "createTime": "2024-02-03 09:18:56",
        "updateTime": "2024-10-31 17:09:37",
        "updateName": "HNCT",
        "mapIndex": null,
        "list": [
            {
                "id": "1753588966113710081",
                "createBy": "6e82717e7e95406ca4f356ce19c4373a",
                "createTime": "2024-02-03 09:19:24",
                "updateBy": null,
                "updateTime": null,
                "floorname": "一楼",
                "buildid": "1753588848392179714",
                "ordernum": null,
                "did": "00d2a14ad64a43c49d0c315e684f00b5",
                "orgCode": "A18",
                "amapLon": 108.998939,
                "amapLat": 34.24687,
                "amapZoom": 10
            },
            {
                "id": "1792839553288011778",
                "createBy": "6e82717e7e95406ca4f356ce19c4373a",
                "createTime": "2024-05-21 16:47:14",
                "updateBy": "hpbgs",
                "updateTime": "2024-09-02 14:37:13",
                "floorname": "二楼",
                "buildid": "1753588848392179714",
                "ordernum": null,
                "did": "00d2a14ad64a43c49d0c315e684f00b5",
                "orgCode": "A18",
                "amapLon": 113.917627,
                "amapLat": 22.654253,
                "amapZoom": 17
            }
        ]
    },
    {
        "id": "1851790904403197953",
        "buildingName": "汽机房",
        "totalfloor": null,
        "createName": "e24104126d7941a2aeefd97513fc5bca",
        "createTime": "2024-10-31 08:58:51",
        "updateTime": "2024-10-31 17:10:27",
        "updateName": "HNCT",
        "mapIndex": null,
        "list": [
            {
                "id": "1851790953254256642",
                "createBy": "e24104126d7941a2aeefd97513fc5bca",
                "createTime": "2024-10-31 08:59:03",
                "updateBy": null,
                "updateTime": null,
                "floorname": "一楼",
                "buildid": "1851790904403197953",
                "ordernum": null,
                "did": "00d2a14ad64a43c49d0c315e684f00b5",
                "orgCode": "A18",
                "amapLon": null,
                "amapLat": null,
                "amapZoom": 30
            }
        ]
    },
    {
        "id": "1851914736615063553",
        "buildingName": "输煤皮带处",
        "totalfloor": null,
        "createName": "e24104126d7941a2aeefd97513fc5bca",
        "createTime": "2024-10-31 17:10:55",
        "updateTime": null,
        "updateName": null,
        "mapIndex": null,
        "list": []
    },
    {
        "id": "1861661609588461569",
        "buildingName": "坪山工厂办公室",
        "totalfloor": null,
        "createName": "0eb6b5edc3b14935899da54c8950d4b9",
        "createTime": "2024-11-27 14:41:30",
        "updateTime": null,
        "updateName": null,
        "mapIndex": null,
        "list": [
            {
                "id": "1861662081024036865",
                "createBy": "0eb6b5edc3b14935899da54c8950d4b9",
                "createTime": "2024-11-27 14:43:23",
                "updateBy": null,
                "updateTime": null,
                "floorname": "1",
                "buildid": "1861661609588461569",
                "ordernum": null,
                "did": "5d5d97d8056041e9ba2c4130b18f01d6",
                "orgCode": "A18A02",
                "amapLon": null,
                "amapLat": null,
                "amapZoom": 30
            }
        ]
    },
    {
        "id": "1861661713552674817",
        "buildingName": "坪山工厂前台",
        "totalfloor": null,
        "createName": "0eb6b5edc3b14935899da54c8950d4b9",
        "createTime": "2024-11-27 14:41:55",
        "updateTime": null,
        "updateName": null,
        "mapIndex": null,
        "list": []
    },
]
const options = ref(temp.map(option => ({
  value: option.buildingName,
  label: option.buildingName,
  children: option.list.map(floor => ({
    value: floor.floorname,
    label: floor.floorname
  }))
})))
const Obar = ref(true)
const activeName = ref('first')
const drawerList = ref()
const drawerList1 = ref()
const profileList = ref()
const groupList = ref()
const groupList1 = ref()

const buttonLoading = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref<Array<string | number>>([])
const total = ref(0)
const total1 = ref(0)
const total2 = ref(0)
const total3 = ref(0)
const total4 = ref(0)

const queryFormRef = ref<FormInstance>()
const profileFormRef = ref<FormInstance>()
const devFormRef = ref<FormInstance>()

const dialog = reactive<DialogOption>({
  visible: false,
  title: '',
})
const dialog1 = reactive<DialogOption>({
  visible: false,
  title: '',
})
// 右侧抽屉-查询>设备列表
const drawer = reactive<DialogOption>({ 
  visible: false,
  title: '',
})

const profileFormData = {
  id: undefined,
  profilename: undefined
}
const data = reactive({
  profileForm: { ...profileFormData },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    profilename: undefined
  },
  devForm: {
    pageNum: 1,
    pageSize: 10
  },

  rules: {
    id: [{ required: true, message: 'id不能为空', trigger: 'blur' }],
    profilename: [{ required: true, message: '情景名称不能为空', trigger: 'blur' }]
  },
})

const { queryParams, devForm , profileForm, rules } = toRefs(data)

/** 查询情景列表 */
const getList = async () => {
  loading.value = true
  profileList.value = [
  {
      "createBy": "e24104126d7941a2aeefd97513fc5bca",
      "instruct": null,
      "sw": 0,
      "createTime": "2024-10-30 17:31:40",
      "updateBy": "HNCT",
      "orgCode": "A18",
      "profilename": "煤仓上班",
      "ld": 0,
      "updateTime": "2024-10-31 17:14:50",
      "id": "1851557570733445122",
      "did": "00d2a14ad64a43c49d0c315e684f00b5"
  },
  {
      "createBy": "e24104126d7941a2aeefd97513fc5bca",
      "instruct": null,
      "sw": 0,
      "createTime": "2024-10-30 17:31:59",
      "updateBy": "HNCT",
      "orgCode": "A18",
      "profilename": "煤仓下班",
      "ld": 0,
      "updateTime": "2024-10-31 17:15:00",
      "id": "1851557649292759042",
      "did": "00d2a14ad64a43c49d0c315e684f00b5"
  },
  {
      "createBy": "e24104126d7941a2aeefd97513fc5bca",
      "instruct": null,
      "sw": 0,
      "createTime": "2024-10-31 17:15:12",
      "updateBy": null,
      "orgCode": "A18",
      "profilename": "电除尘车间上班",
      "ld": 0,
      "updateTime": null,
      "id": "1851915816354742273",
      "did": "00d2a14ad64a43c49d0c315e684f00b5"
  },
  {
      "createBy": "e24104126d7941a2aeefd97513fc5bca",
      "instruct": null,
      "sw": 0,
      "createTime": "2024-10-31 17:15:19",
      "updateBy": null,
      "orgCode": "A18",
      "profilename": "电除尘车间下班",
      "ld": 0,
      "updateTime": null,
      "id": "1851915844553048066",
      "did": "00d2a14ad64a43c49d0c315e684f00b5"
  },
  {
      "createBy": "e24104126d7941a2aeefd97513fc5bca",
      "instruct": null,
      "sw": 0,
      "createTime": "2024-10-31 18:00:30",
      "updateBy": null,
      "orgCode": "A18",
      "profilename": "电除尘车间检修",
      "ld": null,
      "updateTime": null,
      "id": "1851927216544317441",
      "did": "00d2a14ad64a43c49d0c315e684f00b5"
  },
  {
      "createBy": "0eb6b5edc3b14935899da54c8950d4b9",
      "instruct": null,
      "sw": 0,
      "createTime": "2024-12-27 16:10:52",
      "updateBy": null,
      "orgCode": "A18A02",
      "profilename": "下午茶",
      "ld": 0,
      "updateTime": null,
      "id": "1872555735896854530",
      "did": "5d5d97d8056041e9ba2c4130b18f01d6"
  },
  {
      "createBy": "0eb6b5edc3b14935899da54c8950d4b9",
      "instruct": null,
      "sw": 0,
      "createTime": "2024-12-30 17:21:25",
      "updateBy": null,
      "orgCode": "A18A02",
      "profilename": "回路情景",
      "ld": 0,
      "updateTime": null,
      "id": "1873660652023746561",
      "did": "5d5d97d8056041e9ba2c4130b18f01d6"
  }
]
  total.value = 6
  loading.value = false
}

/** 查询设备列表 */
const getDrawerList = async () => {
  loading.value = true
  drawerList.value = [
    {
        "devtype": "单灯控制器",
        "buildingname": "煤仓",
        "imei": "gw000100101035",
        "devname": "煤仓0101001",
        "onlinestate": 1,
        "addr": "56003200",
        "togw": "gw000100101035",
        "floorname": "一楼",
        "groupDevId": "1851927326070177793"
    },
    {
        "devtype": "单灯控制器",
        "buildingname": "煤仓",
        "imei": "gw000100101035",
        "devname": "煤仓0101004",
        "onlinestate": 0,
        "addr": "70090904",
        "togw": "gw000100101035",
        "floorname": "一楼",
        "groupDevId": "1851927326107926529"
    },
    {
        "devtype": "单灯控制器",
        "buildingname": "煤仓",
        "imei": "gw000100101035",
        "devname": "煤仓0101005",
        "onlinestate": null,
        "addr": "70090905",
        "togw": "gw000100101035",
        "floorname": "一楼",
        "groupDevId": "1851927326154063874"
    },
    {
        "devtype": "单灯控制器",
        "buildingname": "煤仓",
        "imei": "gw000100101035",
        "devname": "煤仓0101006",
        "onlinestate": null,
        "addr": "70090906",
        "togw": "gw000100101035",
        "floorname": "一楼",
        "groupDevId": "1851927326200201217"
    },
    {
        "devtype": "单灯控制器",
        "buildingname": "煤仓",
        "imei": "gw000100101035",
        "devname": "煤仓0101007",
        "onlinestate": 1,
        "addr": "70090907",
        "togw": "gw000100101035",
        "floorname": "一楼",
        "groupDevId": "1851927326246338561"
    },
    {
        "devtype": "单灯控制器",
        "buildingname": "煤仓",
        "imei": "gw000100101035",
        "devname": "煤仓0101008",
        "onlinestate": null,
        "addr": "70090908",
        "togw": "gw000100101035",
        "floorname": "一楼",
        "groupDevId": "1851927326288281601"
    },
    {
        "devtype": "单灯控制器",
        "buildingname": "煤仓",
        "imei": "gw000100101035",
        "devname": "煤仓0101009",
        "onlinestate": null,
        "addr": "70090909",
        "togw": "gw000100101035",
        "floorname": "一楼",
        "groupDevId": "1851927326321836034"
    },
    {
        "devtype": "单灯控制器",
        "buildingname": "煤仓",
        "imei": "gw000100101036",
        "devname": "煤仓0101002",
        "onlinestate": null,
        "addr": "70090902",
        "togw": "gw000100101036",
        "floorname": "一楼",
        "groupDevId": "1851927326359584769"
    },
    {
        "devtype": "单灯控制器",
        "buildingname": "煤仓",
        "imei": "gw000100101036",
        "devname": "煤仓0101003",
        "onlinestate": null,
        "addr": "70090903",
        "togw": "gw000100101036",
        "floorname": "一楼",
        "groupDevId": "1851927326393139202"
    }
  ]
  total1.value = 9
  loading.value = false
}

/** 查询设备列表 */
const getDrawerList1 = async () => {
  loading.value = true
  drawerList1.value = [
    {
        "devtype": "单灯控制器",
        "buildingname": "煤仓",
        "imei": "gw000100101035",
        "devname": "煤仓0101007",
        "onlinestate": 1,
        "addr": "70090907",
        "togw": "gw000100101035",
        "floorname": "一楼",
        "groupDevId": "1851927326246338561"
    },
    {
        "devtype": "单灯控制器",
        "buildingname": "煤仓",
        "imei": "gw000100101035",
        "devname": "煤仓0101008",
        "onlinestate": null,
        "addr": "70090908",
        "togw": "gw000100101035",
        "floorname": "一楼",
        "groupDevId": "1851927326288281601"
    },
    {
        "devtype": "单灯控制器",
        "buildingname": "煤仓",
        "imei": "gw000100101035",
        "devname": "煤仓0101009",
        "onlinestate": null,
        "addr": "70090909",
        "togw": "gw000100101035",
        "floorname": "一楼",
        "groupDevId": "1851927326321836034"
    },
    {
        "devtype": "单灯控制器",
        "buildingname": "煤仓",
        "imei": "gw000100101036",
        "devname": "煤仓0101002",
        "onlinestate": null,
        "addr": "70090902",
        "togw": "gw000100101036",
        "floorname": "一楼",
        "groupDevId": "1851927326359584769"
    },
    {
        "devtype": "单灯控制器",
        "buildingname": "煤仓",
        "imei": "gw000100101036",
        "devname": "煤仓0101003",
        "onlinestate": null,
        "addr": "70090903",
        "togw": "gw000100101036",
        "floorname": "一楼",
        "groupDevId": "1851927326393139202"
    }
  ]
  total3.value = 5
  loading.value = false
}

/** 区域 */
const getdevList = async () => {
}

/** 查询群组列表 */
const tabGroupSelect = async () => {
  Obar.value = !Obar.value
  if (!Obar.value) {
    getGroup()
  }
}

/** 查询群组列表 */
const getGroup = async () => {
  loading.value = true
  groupList.value = [
    {
        "createBy": "6e82717e7e95406ca4f356ce19c4373a",
        "createTime": "2024-10-15 16:18:13",
        "updateBy": "HNCT",
        "orgCode": "A18",
        "updateTime": "2024-10-31 17:14:16",
        "sensor": null,
        "id": "1846103270259458049",
        "groupname": "煤仓",
        "groupNo": null,
        "toGw": null,
        "did": "00d2a14ad64a43c49d0c315e684f00b5"
    },
    {
        "createBy": "e24104126d7941a2aeefd97513fc5bca",
        "createTime": "2024-10-31 17:14:22",
        "updateBy": null,
        "orgCode": "A18",
        "updateTime": null,
        "sensor": null,
        "id": "1851915603829358594",
        "groupname": "引风机房",
        "groupNo": null,
        "toGw": null,
        "did": "00d2a14ad64a43c49d0c315e684f00b5"
    },
    {
        "createBy": "e24104126d7941a2aeefd97513fc5bca",
        "createTime": "2024-10-31 17:14:25",
        "updateBy": null,
        "orgCode": "A18",
        "updateTime": null,
        "sensor": null,
        "id": "1851915617280491522",
        "groupname": "调压站",
        "groupNo": null,
        "toGw": null,
        "did": "00d2a14ad64a43c49d0c315e684f00b5"
    },
    {
        "createBy": "e24104126d7941a2aeefd97513fc5bca",
        "createTime": "2024-10-31 17:14:29",
        "updateBy": null,
        "orgCode": "A18",
        "updateTime": null,
        "sensor": null,
        "id": "1851915634460360706",
        "groupname": "检修间",
        "groupNo": null,
        "toGw": null,
        "did": "00d2a14ad64a43c49d0c315e684f00b5"
    },
    {
        "createBy": "0eb6b5edc3b14935899da54c8950d4b9",
        "createTime": "2024-12-27 15:58:31",
        "updateBy": null,
        "orgCode": "A18A02",
        "updateTime": null,
        "sensor": null,
        "id": "1872552623849115650",
        "groupname": "全开1",
        "groupNo": null,
        "toGw": null,
        "did": "5d5d97d8056041e9ba2c4130b18f01d6"
    },
    {
        "createBy": "0eb6b5edc3b14935899da54c8950d4b9",
        "createTime": "2024-12-30 17:15:26",
        "updateBy": null,
        "orgCode": "A18A02",
        "updateTime": null,
        "sensor": null,
        "id": "1873659147929554945",
        "groupname": "回路测试",
        "groupNo": null,
        "toGw": null,
        "did": "5d5d97d8056041e9ba2c4130b18f01d6"
    }
  ]
  total2.value = 6
  loading.value = false
}
/** 查询群组列表 */
const getGroup1 = async () => {
  loading.value = true
  groupList1.value = [
    {
        "createBy": "e24104126d7941a2aeefd97513fc5bca",
        "createTime": "2024-10-31 17:14:25",
        "updateBy": null,
        "orgCode": "A18",
        "updateTime": null,
        "sensor": null,
        "id": "1851915617280491522",
        "groupname": "调压站",
        "groupNo": null,
        "toGw": null,
        "did": "00d2a14ad64a43c49d0c315e684f00b5"
    },
    {
        "createBy": "e24104126d7941a2aeefd97513fc5bca",
        "createTime": "2024-10-31 17:14:29",
        "updateBy": null,
        "orgCode": "A18",
        "updateTime": null,
        "sensor": null,
        "id": "1851915634460360706",
        "groupname": "检修间",
        "groupNo": null,
        "toGw": null,
        "did": "00d2a14ad64a43c49d0c315e684f00b5"
    },
    {
        "createBy": "0eb6b5edc3b14935899da54c8950d4b9",
        "createTime": "2024-12-27 15:58:31",
        "updateBy": null,
        "orgCode": "A18A02",
        "updateTime": null,
        "sensor": null,
        "id": "1872552623849115650",
        "groupname": "全开1",
        "groupNo": null,
        "toGw": null,
        "did": "5d5d97d8056041e9ba2c4130b18f01d6"
    },
    {
        "createBy": "0eb6b5edc3b14935899da54c8950d4b9",
        "createTime": "2024-12-30 17:15:26",
        "updateBy": null,
        "orgCode": "A18A02",
        "updateTime": null,
        "sensor": null,
        "id": "1873659147929554945",
        "groupname": "回路测试",
        "groupNo": null,
        "toGw": null,
        "did": "5d5d97d8056041e9ba2c4130b18f01d6"
    }
  ]
  total4.value = 4
  loading.value = false
}

// 取消按钮
const cancel = () => {
  reset()
  dialog.visible = false
}
// 取消按钮
const cancel1 = () => {
  reset()
  dialog1.visible = false
}
// 表单重置
const reset = () => {
  profileForm.value = { ...profileFormData }
  profileFormRef.value?.resetFields()
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields()
  handleQuery()
}

/** 新增按钮操作 */
const handleAdd = () => {
  dialog.visible = true
  dialog.title = '添加情景'
}

/** 修改按钮操作 */
const handleUpdate = (row) => {
  loading.value = true
  dialog.visible = true
  dialog.title = '修改情景'
  nextTick(async () => {
    loading.value = false
    Object.assign(profileForm.value)
    profileForm.value.profilename = row.profilename
  })
  loading.value = false
}

/** 新增设备按钮操作 */
const handleAddEqu = async (row) => {
  dialog1.visible = true
  dialog1.title = '新增设备' + row.profilename
  // await getdevList()
  await getDrawerList()
}

/** 查询>设备列表操作 */
const handleQueryEqu = (row) => {
  loading.value = true
  drawer.visible = true
  drawer.title = '查看绑定关系--' + row.profilename
  getDrawerList1()
  getGroup1()
  loading.value = false
}
const handleDrawerClose = (value: boolean) => {
  if (!value) {
    drawer.visible = false
  }
};

/** 下发按钮 */
const handleIssue = (row) => {
  proxy?.$modal.msgSuccess('下发成功')
}

/** 提交按钮 */
const submitForm = () => {}

/** 提交按钮 */
const submitForm1 = () => {}

/** 提交按钮 */
const submitForm2 = () => {}

/** 删除按钮操作 */
const handleDelete = async (row) => {
  // let _this = this
  //     let res = await this.getTimedTaskList(v.id)
  //     if (res == undefined) {
  //       this.$message.info(this.$t('search') + this.$t('fail'))
  //       return
  //     }
  //     if (res != -1) {
  //       this.$message.info(
  //         `${this.$t('delete') + this.$t('fail') + '，' + v.profilename + ' ' + this.$t('profilePage.bindds')}`
  //       )
  //       return
  //     }
  ElMessageBox.confirm('是否删除情景-' + row.profilename + '?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    return ElMessage.success('删除成功')
    // deleteAction(`/dk/profile/deleteProfile?id=${row.id}`).then((res) => {
    //   if (res.success) {
    //     ElMessage.success('删除成功')
    //     getList()
    //   } else {
    //     ElMessage.error(res.message)
    //   }
    // })
  })
}

/** 选择条数  */
const handleSelectionChange = (selection) => {
  // ids.value = selection.map((item) => item.id)
}

const tabChange = (tab) => {
  console.log(tab)
  switch (tab) {
    case 'first':
      break
    case 'second':
      break
  }
}

onMounted(() => {
  getList()
})
</script>
<style scoped>
.swld {
  width: 60%;
  height: 40px;
  margin: 0 auto;
  margin-bottom: 15px;
  display: flex;
  align-items: center;
}

.swld p {
  margin-right: 10px;
}

.swld .el-slider {
  flex: 1;
  height: 12px;
  margin-left: 20px;
}
</style>
